home *** CD-ROM | disk | FTP | other *** search
- /* File: meshsym.c
- ** Author: Charles Loop
- ** Purpose: Symbol and Edge table routines required for the creation of a mesh
- ** Last Modified: 2 July, 1987
- ** Reason : Creation.
- */
-
- #include <stdio.h>
- #include "Math.h"
- #include "4D.h"
- #include "mesh.h"
-
- #define SYMBOL_HASH_SIZE 167
- #define EDGE_HASH_SIZE 257
-
- static SymbolEntry *SymbolTable[SYMBOL_HASH_SIZE];
- static EdgeEntry *EdgeTable[EDGE_HASH_SIZE];
-
- SymbolHash(s)
- char *s;
- {
- char *p;
- unsigned h = 0, g;
-
- for (p = s; *p != '\0'; p++) {
- h = (h << 4) + (*p);
- if (g = h&0xf0000000) {
- h = h ^ (g >> 24);
- h = h ^ g;
- }
- }
- return h % SYMBOL_HASH_SIZE;
- }
-
- SymbolEntry *LookupSymbol(s)
- char *s;
- {
- SymbolEntry *sp;
-
- for (sp = SymbolTable[SymbolHash(s)];
- sp != (SymbolEntry *) 0; sp = sp->next)
- if (strcmp(sp->name, s) == 0)
- return sp;
- return (SymbolEntry *) 0;
- }
-
- SymbolEntry *InstallSymbol(s)
- char *s;
- {
- SymbolEntry *sp;
- int hashval;
-
- if ((sp = LookupSymbol(s)) == (SymbolEntry *) 0) {
- sp = (SymbolEntry *) malloc(sizeof(SymbolEntry));
- sp->name = (char *) malloc(sizeof(char)*(strlen(s)+1));
- strcpy(sp->name, s);
- hashval = SymbolHash(sp->name);
- sp->next = SymbolTable[hashval];
- SymbolTable[hashval] = sp;
- }
- return sp;
- }
-
- FreeSymbol()
- {
- SymbolEntry *sp, *tp;
- int i;
-
- for (i = 0; i < SYMBOL_HASH_SIZE; i++) {
- for (sp = SymbolTable[i]; sp != (SymbolEntry *) 0;) {
- tp = sp;
- sp = sp->next;
- free((char *) tp);
- }
- SymbolTable[i] =(SymbolEntry *) 0;
- }
- }
-
- EdgeHash(p,q)
- PointType4D *p,*q;
- {
- return (((unsigned int)p + (unsigned int)q) % EDGE_HASH_SIZE);
- }
-
- Edge *LookupEdge(p,q)
- PointType4D *p,*q;
- {
- EdgeEntry *ep;
-
- for (ep = EdgeTable[EdgeHash(p,q)];
- ep != (EdgeEntry *) 0; ep = ep->next)
- if (ep->p == p && ep->q == q) /* entry found */
- return ep->e;
-
- return (Edge *) 0;
- }
-
- InstallEdge(p,newedge)
- PointType4D *p;
- Edge *newedge;
- {
- EdgeEntry *ep;
- Edge *oldedge;
- PointType4D *q = newedge->p;
- int hashval;
-
- if (oldedge = LookupEdge(q,p)) {
- if (oldedge->e)
- fprintf(stderr, "edge usage conflict\n");
-
- newedge->e = oldedge;
- oldedge->e = newedge;
- }
- else {
- if (LookupEdge(p,q))
- fprintf(stderr, "edge orientation conflict\n");
-
- ep = (EdgeEntry *) malloc(sizeof(EdgeEntry));
- ep->p = p;
- ep->q = q;
- ep->e = newedge;
- hashval = EdgeHash(p,q);
- ep->next = EdgeTable[hashval];
- EdgeTable[hashval] = ep;
- }
- }
-
- FreeEdge()
- {
- EdgeEntry *ep, *tp;
- int i;
-
- for (i = 0; i < EDGE_HASH_SIZE; i++ ) {
- for (ep = EdgeTable[i]; ep != (EdgeEntry *) 0;) {
- if (ep->e) {
- if (ep->e->e)
- free((char *) ep->e->e);
- free((char *) ep->e);
- }
- tp = ep;
- ep = ep->next;
- free((char *) tp);
- }
- EdgeTable[i] = (EdgeEntry *) 0;
- }
-
- }
-
-
-